import { createRouter, createWebHistory} from "vue-router";
import store from '../store'


const routes = [
    {
        meta: {
            title: "luffycity首页站点",
            keepAlive: true,
        },
        path: "/",
        name: "Home",
        component: () => import("../views/Home.vue"),
    },
    {
        meta: {
            title: "luffycity登录",
            keepAlive: true,
        },
        path: "/login",
        name: "Login",
        component: () => import("../views/Login.vue"),
    },
    {
        meta: {
            title: "luffycity用户",
            keepAlive: true,
            authorization: true,
        },
        path: "/user",
        name: "User",
        component: () => import("../views/User.vue"),
    },
    {
        meta: {
            title: "luffycity注册",
            keepAlive: true,
        },
        path: "/register",
        name: "Register",
        component: () => import("../views/Register.vue"),
    },
    {
        meta: {
            title: "luffycity课程",
            keepAlive: true
        },
        path: "/project",
        name: "Course",
        component: () => import("../views/Course.vue"),
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes,
})


router.beforeEach((to, from, next)=>{
  document.title=to.meta.title
  // 登录状态验证
  if (to.meta.authorization && !store.getters.getUserInfo) {
    next({"name": "Login"})
  }else{
    next()
  }
})

export default router